﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace quanlysinhvien
{
    public partial class FormSearch_Student : Form
    {
        public static string Student_Cod;
        SqlConnection conn;
        SqlCommand cmd;
        SqlDataAdapter da;

        DataSet ds;
      //  DataTable dt;
      //  SqlDataReader dr;
        public FormSearch_Student()
        {
            InitializeComponent();
        }

        private void btnSeStuName_Click(object sender, EventArgs e)
        {
            try
            {
                conn = Connect.getConnection();
                conn.Open();
                String strSql = "select Student_Code[Student Code],Class_Code[Class],Faculty_Name[Faculty],Student_Name[Full Name],Student_DOB[Birthday],Student_Sex[Sex],Current_Address[Address],Native_Place[Place],Contact_Address[Contact] from TblStudents where TblStudents.Student_Name like '%" + txtSeStuName.Text + "%'";
                //MessageBox.Show(strSql);
                cmd = new SqlCommand(strSql, conn);
                da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, "student");
                tbShow.DataSource = ds.Tables[0];
                conn.Close();
                txtSeStuName.Clear();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message);
            }

        }

        private void btnSeDOB_Click(object sender, EventArgs e)
        {
            try
            {
                conn = Connect.getConnection();
                conn.Open();
                String strSql = "select Student_Code[Student Code],Class_Code[Class],Faculty_Name[Faculty],Student_Name[Full Name],Student_DOB[Birthday],Student_Sex[Sex],Current_Address[Address],Native_Place[Place],Contact_Address[Contact] from TblStudents where TblStudents.Student_DOB='" + DateTime.Parse(dateSeDOB.Text).ToShortDateString() + "'";
                //MessageBox.Show(strSql);
                cmd = new SqlCommand(strSql, conn);
                da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, "student");
                tbShow.DataSource = ds.Tables[0];
                conn.Close();
                

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message);
            }
        }

        private void btnXemthongtin_Click(object sender, EventArgs e)
        {

        }

        private void btnSeStuCode_Click(object sender, EventArgs e)
        {
            try
            {
                conn = Connect.getConnection();
                conn.Open();
                String strSql = "select Student_Code[Student Code],Class_Code[Class],Faculty_Name[Faculty],Student_Name[Full Name],Student_DOB[Birthday],Student_Sex[Sex],Current_Address[Address],Native_Place[Place],Contact_Address[Contact] from TblStudents where TblStudents.Student_Code like '%" + txtSeStuCode.Text + "%'";
               // MessageBox.Show(strSql);
                cmd = new SqlCommand(strSql, conn);
                da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, "student");
                tbShow.DataSource = ds.Tables[0];
                conn.Close();
                txtSeStuCode.Clear();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex.Message);
            }
        }

        private void bntSeMarStuCod_Click(object sender, EventArgs e)
        {
            try
            {
                conn = Connect.getConnection();
                conn.Open();
                String strSql = "select TblStu_Sub.Student_Code[Student Code],TblStudents.Student_Name[Student Name],TblStu_Sub.Subject_Code[Subject Code],TblStu_Sub.Take_Time[Take Time],TblStu_Sub.Mark[Mark] from TblStu_Sub,TblStudents where TblStudents.Student_Code=TblStu_Sub.Student_Code and TblStu_Sub.Student_Code like '%" + txtSeMarStuCod.Text + "%'";
                //MessageBox.Show(strSql);
              
                cmd = new SqlCommand(strSql, conn);
                da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, "student");
                tbShow.DataSource = ds.Tables[0];
                conn.Close();
                txtSeMarStuCod.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex.Message);
            }
        }

        private void btnSeMarClaCod_Click(object sender, EventArgs e)
        {
            try
            {
                conn = Connect.getConnection();
                conn.Open();
                String strSql = "select TblStudents.Student_Code[Student Code],TblStudents.Class_Code[Class],TblStudents.Student_Name[Student Name],TblStu_Sub.Subject_Code[Subject Code],TblStu_Sub.Mark from TblStudents,TblStu_Sub where TblStudents.Student_Code=TblStu_Sub.Student_Code and TblStudents.Class_Code like '%" + txtSeMarClaCod.Text + "%'";
                //MessageBox.Show(strSql);
                cmd = new SqlCommand(strSql, conn);
                da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, "student");
                tbShow.DataSource = ds.Tables[0];
                conn.Close();
                txtSeMarClaCod.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex.Message);
            }
        }

        private void btnSeMarStuNam_Click(object sender, EventArgs e)
        {
            try
            {
                conn = Connect.getConnection();
                conn.Open();
                String strSql = "select TblStudents.Student_Code[Student Code],TblStudents.Student_Name[Student Name],TblStudents.Class_Code[Class],TblStu_Sub.Subject_Code[Subject Code],TblStu_Sub.Mark from TblStudents,TblStu_Sub where TblStudents.Student_Code=TblStu_Sub.Student_Code and TblStudents.Student_Name like '%" + txtSeMarStuNam.Text + "%'";
               // MessageBox.Show(strSql);
                cmd = new SqlCommand(strSql, conn);
                da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, "student");
                tbShow.DataSource = ds.Tables[0];
                conn.Close();
                txtSeMarStuNam.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex.Message);
            }
        }

        

        private void btnBack_Click(object sender, EventArgs e)
        {
            FormMain FormMain = new FormMain();
            FormMain.Show();
            this.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                conn = Connect.getConnection();
                conn.Open();
                String strSql = "select TblStudents.Student_Code[Student Code],TblStu_Sub.Subject_Code[Subject Code],TblStudents.Student_Name[Student Name],TblStudents.Class_Code[Class],TblStu_Sub.Mark from TblStudents,TblStu_Sub,TblSubject where TblStudents.Student_Code=TblStu_Sub.Student_Code and TblSubject.Subject_Code=TblStu_Sub.Subject_Code and TblSubject.Subject_Code like '%" + txtSeMarBySub.Text + "%'";
               // MessageBox.Show(strSql);
                cmd = new SqlCommand(strSql, conn);
                da = new SqlDataAdapter(cmd);
                ds = new DataSet();
                da.Fill(ds, "student");
                tbShow.DataSource = ds.Tables[0];
                conn.Close();
                txtSeMarBySub.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + ex.Message);
            }
        }

        private void btnMore_Click(object sender, EventArgs e)
        {
           
                Student_Cod = tbShow.CurrentRow.Cells[0].Value.ToString();
                FormView FormView = new FormView();
                FormView.Show();
            
        }
        

 
    }
}
